package main

import "fmt"

func solution(n int, c int) int {
    if n <= 1 {
        return c
    }
    if n%2 == 0 {
        return solution(n/2, c+n/2)
    }
    return solution((n-1)/2+1, c+(n-1)/2)
}

func main() {
    fmt.Println(solution(7, 0) == 6)   // true
    fmt.Println(solution(14, 0) == 13) // true
    fmt.Println(solution(1, 0) == 0)   // true
}
